package com.jgp.workflow.service;

import com.jgp.common.pojo.TreeBean;
import com.jgp.security.secmodel.SecUser;
import com.jgp.sys.ui.Pager;
import com.jgp.workflow.exception.WorkflowException;
import com.jgp.workflow.pojo.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2018/11/26
 */
public interface ProcessService {
    
    Boolean publishProcess(String modelId) throws IOException;
    
    /**
     * 启动流程
     *
     * @param tenantId    业务系统ID
     * @param defKey      流程定义key
     * @param businessKey 业务主键
     * @param variables   全局变量
     * @return
     * @throws WorkflowException
     */
    Map<String, Object> start(String userId, String tenantId, String defKey, String businessKey, Map<String, Object> variables) throws
            WorkflowException;
    
    List<ViewProcessTask> getActiveTask(String procId);
    
    ViewProcessTask getTaskByProcIdAndTaskDefKey(String procId,String taskDefKey);
    
    List<ViewTaskDefinition> getNextTaskDefinition(String procId);
    
    /**
     * 获取任务节点最后处理人
     * @param taskId
     * @return
     */
    String getTaskLastAssignee(String procId,String taskId);
    /**
     * 设置处理人
     * @param taskId
     * @param userId
     */
    void setAssignee(String taskId,String userId);
    
    /**
     * 多实例加签
     * @param taskId
     * @param assigneeList
     */
    void addMultiInstanceExecution(String taskId, List<String> assigneeList);
    
    /**
     * 设置候选人
     * @param taskId
     * @param userIds
     */
    void setCandidate(String taskId,String ... userIds);
    
    /**
     * 把任务授权给其他人
     * @param taskId
     * @param owner 任务持有人
     * @param assignee 处理人
     */
    void grantTo(String taskId,String owner,String assignee);
    /**
     * @param procId    流程实例Id
     * @param taskId    任务Id
     * @param remark    备注
     * @param variables 【全局】变量 作用域整个流程实例
     * @throws WorkflowException
     */
    void completeWithGlobalVariables(String userId, String procId, String taskId, Map<String, Object> variables, String remark) throws
            WorkflowException;
    
    /**
     * @param procId    流程实例Id
     * @param taskId    任务Id
     * @param remark    备注
     * @param variables 【局部】变量 作用域当前任务节点
     * @throws WorkflowException
     */
    void completeWithLocalVariables(String userId, String procId, String taskId, Map<String, Object> variables, String remark) throws
            WorkflowException;
    
    /**
     * @param procId 流程实例Id
     * @param taskId 任务Id
     * @param remark 备注
     * @throws WorkflowException
     */
    void complete(String userId, String procId, String taskId, String remark) throws WorkflowException;
    
    void backTarget(String userId, String procId, String taskId, String targetTaskKey, String remark);
    
    void backTargetAndSetCandidate(String userId, String procId, String taskId, String targetTaskKey, String remark, List<TargetPerson> targetPersons);
    
    InputStream queryProcessStatePic(String processInsId);
    
    InputStream queryProcessPic(String defKey);
    
    List<ViewProcessTask> queryCompletedTask(String userId, Pager pager);
    
    List<ViewProcessTask> queryNotHandledTask(String userId, String sn, String procName,String taskName, List<String> groupIds, List<String> institutionIds, Pager pager);
    
    List<ViewProcessTask> queryApplyButNotPass(String userId, Pager pager);
    
    ViewProcessTask queryNotHandledTaskByTaskId(String taskId);
    
    List<ViewProcessTask> queryProcessTaskFlowed(String procId, Pager pager);
    
    List<ViewProcessIns> queryWorkOrder(QueryWorkOrderForm queryForm, Pager pager);
    
    List<ViewProcessDef> queryAllProcessDef(Pager pager);
    
    String getCustomForm(String procId, String taskId, String userId, Boolean editFlag);
    
    ViewProcessIns queryOneProcessIns(String procId);
    
    ViewProcessIns queryOneProcessInsBySn(String sn);
    
    List<TreeBean> queryTasksByProcForTree(String procId);
    
    List<String> queryRunTimeBusinessKeyByTaskDefIdAndProcDefId(String procDefId, String taskDefId);
    
    List<ViewProcessTask> queryActiveTasksByUserAndTaskDefKey(String userId, String procId, String taskDefKey);
    
    List<ViewProcessTask> queryActiveTasksByUserAndTaskDefKey(List<Long> roleIds,List<Long> orgIds, String procId, String taskDefKey);
    
    void claim(String userId, String taskId, String remark) throws WorkflowException;
    
    void unClaim(String userId, String taskId, String remark) throws WorkflowException;
    
    List<TaskComment> queryTaskComments(String taskId);
    
    List<TaskComment> queryTaskComments(String procId, String taskDefKey);
    
    TaskComment queryLastTaskComments(String taskId);
    
    TaskComment queryLastTaskCommentByProcIdAndTaskDefkey(String procId, String taskDefKey);
    
    List<SecUser> queryTasksAssignees(String procId, String taskDefKey);
    
    List<SecUser> queryTasksAssignees(String procId, List<String> taskDefKeys);
    
    void removeProcIns(String procId,String reason);
    
    List<ViewProcessIns> queryProcessIns(List<String> businessKeys);
    
    ViewProcessIns queryOneProcessInsByBusinessKey(String businessKey);
    
    void makeTop(String procId);
    
    void makeUnTop(String procId);
}
